package com.bibibx;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.bibibx.filter.SwaggerEnableFilter;

@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan({ "com.bibibx" })
public class Application extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);
	}
	
	public static void main(String[] args) throws Exception {
		SpringApplication.run(Application.class, args);
	}
	
	@Bean
	public SwaggerEnableFilter swaggerFilter(){
		return new SwaggerEnableFilter();
	}
	
	@Bean
	public FilterRegistrationBean swaggerPage(SwaggerEnableFilter sf){
		FilterRegistrationBean filter = new FilterRegistrationBean();
		filter.setFilter(sf);
		filter.addUrlPatterns("/swagger-ui.html");
		return filter;
	}
	
}